# lc1
lc1_lab <- iv_robust(lc1 ~ absenteeism | Z_absenteeism, data = lab,diagnostics = T)

lc1_lab_pvals <- getParametricPValue(model = lc1_lab,
																		 hypothesis = "upr")

#pta
pta_lab <- iv_robust(pta ~ absenteeism | Z_absenteeism, data = lab)
pta_lab_pvals <- getParametricPValue(model = pta_lab,
																		 hypothesis = "upr")

# bring_up
bring_up_lab <- iv_robust(bring_up ~ absenteeism | Z_absenteeism, data = lab)
bring_up_lab_pvals <- getParametricPValue(model = bring_up_lab,
																		 hypothesis = "upr")

#assemble
assemble_lab <- iv_robust(assemble ~ absenteeism | Z_absenteeism, data = lab)
assemble_lab_pvals <- getParametricPValue(model = assemble_lab,
																					hypothesis = "upr")

# absenteeism_action
absenteeism_action_lab <- iv_robust(absenteeism_action ~ absenteeism | Z_absenteeism, data = lab)
absenteeism_action_lab_pvals <- getParametricPValue(model = absenteeism_action_lab,
																					hypothesis = "upr")

#setup
control_means <- with(
	lab, 
	c(
		round(mean(lc1[Z_absenteeism == 0],na.rm = TRUE), 2),
		round(mean(bring_up[Z_absenteeism == 0],na.rm = TRUE), 2),
		round(mean(pta[Z_absenteeism == 0],na.rm = TRUE), 2),
		round(mean(assemble[Z_absenteeism == 0],na.rm = TRUE), 2),
		round(mean(absenteeism_action[Z_absenteeism == 0],na.rm = TRUE), 2)
	)
)
control_means <- as.character(control_means)

pval_lines <- c(
	round(lc1_lab_pvals["absenteeism"],3),
	round(bring_up_lab_pvals["absenteeism"],3),
	round(pta_lab_pvals["absenteeism"],3),
	round(assemble_lab_pvals["absenteeism"],3),
	round(absenteeism_action_lab_pvals["absenteeism"],3)
)

hypothesis_lines <- c(
	"upr",
	"upr",
	"upr",
	"upr",
	"upr"
)

sink("03_tables/ABS_attitudes_lab_Z_iv.tex")
print(texreg(l = list(lc1_lab,
								bring_up_lab,
								pta_lab,
								assemble_lab,
								absenteeism_action_lab),
			 omit.coef = "Intercept", include.rsquared = F,include.rmse = F,
			 table = F, use.packages = F, custom.gof.names = c("Adjusted R^2", "Observations"),
			 digits = 3, include.ci = FALSE,
			 override.pvalues = list(lc1_lab_pvals,
			 												bring_up_lab_pvals,
			 												pta_lab_pvals, 
			 												assemble_lab_pvals,
			 												absenteeism_action_lab_pvals),
			 stars = c(0.01, 0.05, 0.1),
			 custom.header = list("Involve LC1 Chair" = 1, 
			 										 "Tell village" = 2,
			 										 "Use PTA" = 3,
			 										 "Assemble group" = 4,
			 										 "Index" = 5),
			 custom.model.names =  c("(1)",
			 												"(2)",
			 												"(3)",
			 												"(4)",
			 												"(5)"),
			 custom.gof.rows = list(
			 	"Control Mean" = control_means,
			 	"$p$-values" = pval_lines,
			 	"Hypothesis" = hypothesis_lines,
			 	"Block FE" = c("No","No","No","No",
			 		"No")),
			 reorder.gof = c(1,2,3,4,6,5)))
sink()


# First stage F-statistic -------------------------------------------------

lc1_lab$diagnostic_first_stage_fstatistic
